layui.use(['upload','layer'],function () {
    var upload = layui.upload
        ,$  =layui.jquery
        ,layer = layui.layer

    //拖拽上传
    upload.render({
        elem: '#uploadDiv'
        ,url: 'http://changtuchacha.com/api/EdgePlug/qiniuyun_plug'
        ,data:JSON.parse(localStorage.getItem('qiniuyun'))
        ,accept:"file"
        ,method:"post"
        ,before:function () {
            $("#pathDiv").hide()
            layer.load();
        }
        ,done: function(res, index, upload){
            layui.$('#uploadView').removeClass('layui-hide').find('img').attr('src', res.src);
            layer.closeAll('loading');
            layer.msg('上传成功',{icon:1,time:1000},function () {
                $("#pathDiv").show()
                $("#htmlText").val("<img src='"+res.src+"'>")
                $("#mkText").val("![avatar]("+res.src+")")
                $("#urlText").val(res.src)
            });
        }
    });

    $("#urlBtn").click(function () {
        // 获取Dom节点
        var copy = document.getElementById("urlText");
        //  用select函数将文本内容选中
        copy.select();
        document.execCommand('Copy');
        layer.msg("复制成功")
    })
    $("#htmlBtn").click(function () {
        // 获取Dom节点
        var copy = document.getElementById("htmlText");
        //  用select函数将文本内容选中
        copy.select();
        document.execCommand('Copy');
        layer.msg("复制成功")
    })
    $("#mkBtn").click(function () {
        // 获取Dom节点
        var copy = document.getElementById("mkText");
        //  用select函数将文本内容选中
        copy.select();
        document.execCommand('Copy');
        layer.msg("复制成功")
    })
})
